import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:getuiflut/getuiflut.dart';
import 'package:provider/provider.dart';
import 'package:ytbusiness/page/init_app.dart';
import 'package:ytbusiness/routes.dart';
import 'package:ytbusiness/state/app_providers.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // 强制竖屏
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  if (Platform.isAndroid) {
    // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，
    // 是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.dark,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
  /**
   *初始化个推sdk
   */
  Getuiflut.initGetuiSdk;

  ///开启推送
  Getuiflut().turnOnPush();

  runApp(MultiProvider(
    providers: providers,
    child: MyApp(),
  ));
}

///root widget
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: '云途养护',
      theme: ThemeData(
        backgroundColor: Color(0xfff4f4f4),
        appBarTheme: AppBarTheme(
          brightness: Brightness.light,
          color: Color.fromRGBO(255, 255, 255, 1),
          elevation: 0.0,
          iconTheme: IconThemeData(color: Colors.black),
        ),
        splashColor: Colors.transparent,
        //全局按钮背景色
        buttonColor: Color.fromRGBO(255, 224, 88, 1),
      ),
      //默认启动页面
      initialRoute: RouteManager.initApp,
      onGenerateRoute: RouteManager.onGenerateRoute,
      onUnknownRoute: (RouteSettings settings) => MaterialPageRoute<void>(
          settings: settings, builder: (BuildContext context) => InitApp()),
    );
  }
}
